<?php
namespace app\common\model;

// use think\Model;

class ProcessAudit extends \app\common\model\Base
{




    //系统支持自动写入创建和更新的时间戳字段
    //protected $autoWriteTimestamp = true;

    //类型自动转换
    protected $type = [
        'id'    =>  'integer',           // 规则id  
    ];




    protected static function init()
    {
        

    }

    /**
     * 获取审核流程
     * @return [type] [description]
     */
    public function  getAudits( $process_id ){

        $rs = $this->where('id',$process_id)->order('step')->select();
        $arr = array();
        $tree = model('Role')->tree;
        foreach($rs as $k => $v){
            $p = array();
            foreach( $tree->getPos($v['role_id']) as $pv){
                $p[] = $pv['name'];
            }
            $v['place'] = implode( ' / ' , $p);

            $p = array();
            foreach( $v->role->users  as $pv){
                $p[] = $pv['username'];
            }
            $v['users_name'] = implode( ' , ' , $p);



            $arr[$v['step']][] = $v;
        }
        unset($rs);
        $arr2  = array();
        foreach ($arr as $k => $v) {
            $arr2[] = $v;
        }

        return $arr2;

    }

    //关联表user表1 : 1 
    public function role()
    {
        return $this->hasOne('role','id','role_id');
    }

    //关联表user表1 : 1 
    public function users()
    {
        return $this->belongsToMany('user','user_role','role_id','role_id');// 关联表  关系表    关系表.字段 = 关联表.字段
    }


	


}